﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Protocol
{
    public class ResCreateFightRoom
    {
        public int Area;
        public List<int> RoldIds = new List<int>();
        public byte[] Encode()
        {
            byte[] buffer;
            using (MemoryStreamExt ms = new MemoryStreamExt())
            {
                ms.WriteInt(Area);
                ms.WriteInt(RoldIds.Count);
                for (int i = 0; i < RoldIds.Count; i++)
                {
                    ms.WriteInt(RoldIds[i]);
                }
                buffer = new byte[ms.Length];
                buffer = ms.GetBuffer();
            }
            return buffer;
        }

        public static ResCreateFightRoom Decode(byte[] buffer)
        {
            ResCreateFightRoom res = new ResCreateFightRoom();
            using (MemoryStreamExt ms = new MemoryStreamExt(buffer))
            {
                res.Area = ms.ReadInt();
                int count = ms.ReadInt();
                res.RoldIds = new List<int>();
                for (int i = 0; i < count; i++)
                {
                    res.RoldIds.Add(ms.ReadInt());
                }
            }
            return res;
        }
    }
}
